package org.dicr.util.protect;

import java.util.*;
import java.util.prefs.*;

/**
 * <p>
 * Title: Akusher
 * </p>
 * <p>
 * Description: Akusher Database
 * </p>
 * <p>
 * Copyright: Copyright (c) 2003
 * </p>
 * <p>
 * Company: Dicr
 * </p>
 * 
 * @author Igor Tarasov, linux@dicr.org
 * @version 1.0
 */

public class FinalTime {
	long finaltime = Long.MAX_VALUE;

	public FinalTime() {
		super();
	}

	public FinalTime(long theFinalTime) {
		this.setFinal(theFinalTime);
	}

	public void setFinal(long time) {
		this.finaltime = time;
	}

	public void setFinal(Date date) {
		this.finaltime = date.getTime();
	}

	public void setFinal(Calendar cal) {
		this.finaltime = cal.getTimeInMillis();
	}

	public void read(Class<?> c) {
		Preferences prefs = Preferences.userNodeForPackage(c);
		this.finaltime = prefs.getLong("fut", System.currentTimeMillis());
	}

	public void save(Class<?> c) {
		Preferences prefs = Preferences.userNodeForPackage(c);
		prefs.putLong("fut", this.finaltime);
	}

	public void checkFinal() throws IllegalStateException {
		if (System.currentTimeMillis() > this.finaltime) { throw new IllegalStateException("Plachido Nekuda"); }
	}
}
